from pydantic import BaseModel
from typing import Optional, List, Dict, Any
from app.models.question import QuestionType


class QuestionBase(BaseModel):
    question_type: QuestionType
    title: str
    content: Optional[str] = None
    options: Optional[List[Dict[str, Any]]] = None  # JSON格式
    correct_answer: str
    score: float = 1.0
    order_num: int = 0
    difficulty: int = 1
    explanation: Optional[str] = None


class QuestionCreate(QuestionBase):
    exam_id: int


class QuestionUpdate(BaseModel):
    question_type: Optional[QuestionType] = None
    title: Optional[str] = None
    content: Optional[str] = None
    options: Optional[List[Dict[str, Any]]] = None
    correct_answer: Optional[str] = None
    score: Optional[float] = None
    order_num: Optional[int] = None
    difficulty: Optional[int] = None
    explanation: Optional[str] = None


class QuestionResponse(QuestionBase):
    id: int
    exam_id: int

    class Config:
        from_attributes = True


class QuestionForStudent(BaseModel):
    id: int
    question_type: QuestionType
    title: str
    content: Optional[str] = None
    options: Optional[List[Dict[str, Any]]] = None
    score: float
    order_num: int

    class Config:
        from_attributes = True